/*    */ package com.zimbra.cs.mailclient.auth;
/*    */ 
/*    */ import com.zimbra.cs.mailclient.MailConfig;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import javax.security.auth.login.LoginException;
/*    */ import javax.security.sasl.SaslException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public final class AuthenticatorFactory
/*    */ {
/*    */   private Map<String, Info> authenticators;
/* 34 */   private static final AuthenticatorFactory DEFAULT = new AuthenticatorFactory();
/*    */   
/*    */   public static AuthenticatorFactory getDefault()
/*    */   {
/* 38 */     return DEFAULT;
/*    */   }
/*    */   
/*    */   public AuthenticatorFactory() {
/* 42 */     this.authenticators = new HashMap();
/* 43 */     register("PLAIN", SaslAuthenticator.class);
/* 44 */     register("GSSAPI", SaslAuthenticator.class, false);
/* 45 */     register("CRAM-MD5", SaslAuthenticator.class);
/* 46 */     register("DIGEST-MD5", SaslAuthenticator.class);
/*    */   }
/*    */   
/*    */   public Authenticator newAuthenticator(MailConfig config, String password) throws LoginException, SaslException
/*    */   {
/* 51 */     String mechanism = config.getMechanism();
/* 52 */     if (mechanism == null) {
/* 53 */       throw new IllegalArgumentException("Missing required mechanism");
/*    */     }
/* 55 */     Info info = (Info)this.authenticators.get(mechanism);
/* 56 */     if (info == null) {
/* 57 */       return null;
/*    */     }
/*    */     Authenticator auth;
/*    */     try {
/* 61 */       auth = (Authenticator)info.clazz.newInstance();
/*    */     } catch (Exception e) {
/* 63 */       throw new IllegalStateException("Unable to instantiate class: " + info.clazz, e);
/*    */     }
/* 65 */     auth.init(config, password);
/* 66 */     return auth;
/*    */   }
/*    */   
/*    */   public boolean isPasswordRequired(String mechanism) {
/* 70 */     Info info = (Info)this.authenticators.get(mechanism);
/* 71 */     return (info != null) && (info.passwordRequired);
/*    */   }
/*    */   
/*    */   public Authenticator newAuthenticator(MailConfig config) throws LoginException, SaslException
/*    */   {
/* 76 */     return newAuthenticator(config, null);
/*    */   }
/*    */   
/*    */   public void register(String mechanism, Class<? extends Authenticator> clazz, boolean passwordRequired) {
/* 80 */     Info info = new Info(null);
/* 81 */     info.clazz = clazz;
/* 82 */     info.passwordRequired = passwordRequired;
/* 83 */     this.authenticators.put(mechanism, info);
/*    */   }
/*    */   
/*    */   public void register(String mechanism, Class<? extends Authenticator> clazz) {
/* 87 */     register(mechanism, clazz, true);
/*    */   }
/*    */   
/*    */   private static class Info
/*    */   {
/*    */     Class<? extends Authenticator> clazz;
/*    */     boolean passwordRequired;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/auth/AuthenticatorFactory.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */